package com.only4play.system.web;

import com.only4play.common.model.JsonObject;
import com.only4play.common.model.PageRequestWrapper;
import com.only4play.common.model.PageResult;
import com.only4play.productcenter.api.goods.request.GoodsCreateRequest;
import com.only4play.productcenter.api.goods.request.GoodsInStoreRequest;
import com.only4play.productcenter.api.goods.request.GoodsQueryRequest;
import com.only4play.productcenter.api.goods.request.GoodsUpdateRequest;
import com.only4play.productcenter.api.goods.response.GoodsResponse;
import com.only4play.productcenter.api.goods.service.GoodsFeignService;
import com.only4play.system.mapper.GoodsMapper;
import com.only4play.system.req.AgentGoodsInReq;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author hinzzz www.hinzzz.cn 157957329@qq.com
 * 2024-02-27
 */
@RestController
@RequestMapping(value = "goods")
@Schema(title = "goods")
@RequiredArgsConstructor
public class GoodsController {

    private final GoodsFeignService goodsFeignService;


    /**
     * 商品入库
     */
    @PostMapping("goodsIn")
    public JsonObject<String> goodsIn(@RequestBody AgentGoodsInReq request) {
        GoodsInStoreRequest goodsInStoreRequest = GoodsMapper.INSTANCE.dtoToEntity(request);
        return goodsFeignService.goodsInStore(goodsInStoreRequest);
    }

    /**
     * createRequest
     */
    @PostMapping("createGoods")
    public JsonObject<Long> createGoods(@RequestBody GoodsCreateRequest request) {
        return goodsFeignService.createGoods(request);
    }

    /**
     * update request
     */
    @PostMapping("updateGoods")
    public JsonObject<String> updateGoods(@RequestBody GoodsUpdateRequest request) {
        return goodsFeignService.updateGoods(request);
    }

    /**
     * valid
     */
    @PostMapping("valid/{id}")
    public JsonObject<String> validGoods(@PathVariable Long id) {
        return goodsFeignService.validGoods(id);
    }

    /**
     * invalid
     */
    @PostMapping("invalid/{id}")
    public JsonObject<String> invalidGoods(@PathVariable Long id) {
        return goodsFeignService.invalidGoods(id);
    }

    /**
     * findById
     */
    @GetMapping("findById/{id}")
    public JsonObject<GoodsResponse> findById(@PathVariable Long id) {
        return goodsFeignService.findById(id);
    }

    /**
     * findByPage request
     */
    @PostMapping("findByPage")
    public JsonObject<PageResult<GoodsResponse>> findByPage(
            @RequestBody PageRequestWrapper<GoodsQueryRequest> request) {
        return goodsFeignService.findByPage(request);
    }

}

